//===================================================================
// 项目名 : Hbt.Cur
// 文件名 : HbtEngineController.cs
// 创建者 : Claude
// 创建时间: 2024-12-01
// 版本号 : V0.0.1
// 描述    : 工作流引擎控制器
//===================================================================

using Hbt.Application.Dtos.Workflow;
using Hbt.Application.Services.Workflow.Engine;
using Hbt.Application.Services.Workflow.Engine.Parallel;
using Hbt.Application.Services.Workflow.Engine.Scheduler;

namespace Hbt.WebApi.Controllers.Workflow;

/// <summary>
/// 工作流引擎控制器 - 统一工作流管理
/// </summary>
[ApiController]
[Route("api/[controller]", Name = "工作流引擎")]
[ApiModule("workflow", "工作流管理")]
[Authorize]
public class HbtEngineController : HbtBaseController
{
    private readonly IHbtWorkflowEngine _workflowEngine;
    private readonly IHbtParallelWorkflowEngine _parallelWorkflowEngine;
    private readonly IHbtWorkflowScheduler _workflowScheduler;

    public HbtEngineController(IHbtWorkflowEngine workflowEngine,
        IHbtParallelWorkflowEngine parallelWorkflowEngine,
        IHbtWorkflowScheduler workflowScheduler,
        IHbtLogger logger,
        IHbtCurrentUser currentUser,
        IHbtLocalizationService localizationService) : base(logger, currentUser, localizationService)
    {
        _workflowEngine = workflowEngine ?? throw new ArgumentNullException(nameof(workflowEngine));
        _parallelWorkflowEngine = parallelWorkflowEngine ?? throw new ArgumentNullException(nameof(parallelWorkflowEngine));
        _workflowScheduler = workflowScheduler ?? throw new ArgumentNullException(nameof(workflowScheduler));
    }

    /// <summary>
    /// 启动工作流实例
    /// </summary>
    /// <param name="dto">启动参数</param>
    /// <returns>工作流实例ID</returns>
    [HttpPost("start")]
    [HbtPerm("workflow:engine:execution:start")]
    public async Task<IActionResult> StartAsync([FromBody] HbtWorkflowStartDto dto)
    {
        try
        {
            if (dto == null)
                return Error("请求参数不能为空");

            var instanceId = await _workflowEngine.StartAsync(dto);
            return Success(instanceId, "工作流启动成功");
        }
        catch (Exception ex)
        {
            return Error(ex.Message);
        }
    }

    /// <summary>
    /// 暂停工作流实例
    /// </summary>
    /// <param name="instanceId">工作流实例ID</param>
    /// <param name="reason">暂停原因</param>
    /// <returns>是否成功</returns>
    [HttpPost("{instanceId}/suspend")]
    [HbtPerm("workflow:engine:execution:suspend")]
    public async Task<IActionResult> SuspendAsync(long instanceId, [FromQuery] string reason = "手动暂停")
    {
        try
        {
            await _workflowEngine.SuspendAsync(instanceId, reason);
            return Success(true, "工作流暂停成功");
        }
        catch (Exception ex)
        {
            return Error(ex.Message);
        }
    }

    /// <summary>
    /// 恢复工作流实例
    /// </summary>
    /// <param name="instanceId">工作流实例ID</param>
    /// <returns>是否成功</returns>
    [HttpPost("{instanceId}/resume")]
    [HbtPerm("workflow:engine:execution:resume")]
    public async Task<IActionResult> ResumeAsync(long instanceId)
    {
        try
        {
            await _workflowEngine.ResumeAsync(instanceId);
            return Success(true, "工作流恢复成功");
        }
        catch (Exception ex)
        {
            return Error(ex.Message);
        }
    }

    /// <summary>
    /// 终止工作流实例
    /// </summary>
    /// <param name="instanceId">工作流实例ID</param>
    /// <param name="reason">终止原因</param>
    /// <returns>是否成功</returns>
    [HttpPost("{instanceId}/terminate")]
    [HbtPerm("workflow:engine:execution:terminate")]
    public async Task<IActionResult> TerminateAsync(long instanceId, [FromQuery] string reason)
    {
        try
        {
            if (string.IsNullOrEmpty(reason))
                return Error("终止原因不能为空");

            await _workflowEngine.TerminateAsync(instanceId, reason);
            return Success(true, "工作流终止成功");
        }
        catch (Exception ex)
        {
            return Error(ex.Message);
        }
    }

    /// <summary>
    /// 审批工作流
    /// </summary>
    /// <param name="dto">审批参数</param>
    /// <returns>是否成功</returns>
    [HttpPost("approve")]
    [HbtPerm("workflow:engine:signoff:approve")]
    public async Task<IActionResult> ApproveAsync([FromBody] HbtWorkflowApproveDto dto)
    {
        try
        {
            if (dto == null)
                return Error("请求参数不能为空");

            var result = await _workflowEngine.ApproveAsync(dto);
            if (result)
                return Success(true, "审批操作成功");
            else
                return Error("审批操作失败");
        }
        catch (Exception ex)
        {
            return Error(ex.Message);
        }
    }

    /// <summary>
    /// 获取工作流实例状态
    /// </summary>
    /// <param name="instanceId">工作流实例ID</param>
    /// <returns>工作流实例状态</returns>
    [HttpGet("{instanceId}/status")]
    [HbtPerm("workflow:engine:execution:query")]
    public async Task<IActionResult> GetStatusAsync(long instanceId)
    {
        try
        {
            var result = await _workflowEngine.GetStatusAsync(instanceId);
            return Success(result);
        }
        catch (Exception ex)
        {
            return Error(ex.Message);
        }
    }

    /// <summary>
    /// 获取工作流实例可用转换列表
    /// </summary>
    /// <param name="instanceId">工作流实例ID</param>
    /// <returns>可用转换列表</returns>
    [HttpGet("{instanceId}/transitions")]
    [HbtPerm("workflow:engine:execution:query")]
    public async Task<IActionResult> GetAvailableTransitionsAsync(long instanceId)
    {
        try
        {
            var result = await _workflowEngine.GetAvailableTransitionsAsync(instanceId);
            return Success(result);
        }
        catch (Exception ex)
        {
            return Error(ex.Message);
        }
    }

    /// <summary>
    /// 获取工作流实例当前节点信息
    /// </summary>
    /// <param name="instanceId">工作流实例ID</param>
    /// <returns>当前节点信息</returns>
    [HttpGet("{instanceId}/current-node")]
    [HbtPerm("workflow:engine:execution:query")]
    public async Task<IActionResult> GetCurrentNodeAsync(long instanceId)
    {
        try
        {
            var result = await _workflowEngine.GetCurrentNodeAsync(instanceId);
            return Success(result);
        }
        catch (Exception ex)
        {
            return Error(ex.Message);
        }
    }

    /// <summary>
    /// 获取工作流实例变量
    /// </summary>
    /// <param name="instanceId">工作流实例ID</param>
    /// <returns>工作流变量字典</returns>
    [HttpGet("{instanceId}/variables")]
    [HbtPerm("workflow:engine:execution:query")]
    public async Task<IActionResult> GetVariablesAsync(long instanceId)
    {
        try
        {
            var result = await _workflowEngine.GetVariablesAsync(instanceId);
            return Success(result);
        }
        catch (Exception ex)
        {
            return Error(ex.Message);
        }
    }

    /// <summary>
    /// 设置工作流实例变量
    /// </summary>
    /// <param name="instanceId">工作流实例ID</param>
    /// <param name="variables">变量字典</param>
    /// <returns>是否成功</returns>
    [HttpPut("{instanceId}/variables")]
    [HbtPerm("workflow:engine:execution:update")]
    public async Task<IActionResult> SetVariablesAsync(long instanceId, [FromBody] Dictionary<string, object> variables)
    {
        try
        {
            if (variables == null)
                return Error("变量不能为空");

            await _workflowEngine.SetVariablesAsync(instanceId, variables);
            return Success(true, "变量设置成功");
        }
        catch (Exception ex)
        {
            return Error(ex.Message);
        }
    }

    /// <summary>
    /// 获取工作流实例历史记录
    /// </summary>
    /// <param name="instanceId">工作流实例ID</param>
    /// <returns>历史记录列表</returns>
    [HttpGet("{instanceId}/history")]
    [HbtPerm("workflow:engine:execution:query")]
    public async Task<IActionResult> GetHistoryAsync(long instanceId)
    {
        try
        {
            var result = await _workflowEngine.GetHistoryAsync(instanceId);
            return Success(result);
        }
        catch (Exception ex)
        {
            return Error(ex.Message);
        }
    }

    /// <summary>
    /// 获取工作流实例操作记录
    /// </summary>
    /// <param name="instanceId">工作流实例ID</param>
    /// <returns>操作记录列表</returns>
    [HttpGet("{instanceId}/operations")]
    [HbtPerm("workflow:engine:execution:query")]
    public async Task<IActionResult> GetOperationsAsync(long instanceId)
    {
        try
        {
            var result = await _workflowEngine.GetOperationsAsync(instanceId);
            return Success(result);
        }
        catch (Exception ex)
        {
            return Error(ex.Message);
        }
    }

    // 转换历史相关接口

    /// <summary>
    /// 获取转换历史列表
    /// </summary>
    /// <param name="query">查询条件</param>
    /// <returns>转换历史列表</returns>
    [HttpGet("transition/list")]
    [HbtPerm("workflow:engine:execution:query")]
    public async Task<IActionResult> GetTransitionListAsync([FromQuery] HbtInstanceTransQueryDto query)
    {
        try
        {
            var result = await _workflowEngine.GetTransitionListAsync(query);
            return Success(result);
        }
        catch (Exception ex)
        {
            return Error(ex.Message);
        }
    }

    /// <summary>
    /// 获取转换历史详情
    /// </summary>
    /// <param name="transitionId">转换ID</param>
    /// <returns>转换历史详情</returns>
    [HttpGet("transition/{transitionId}")]
    [HbtPerm("workflow:engine:execution:query")]
    public async Task<IActionResult> GetTransitionAsync(string transitionId)
    {
        try
        {
            var result = await _workflowEngine.GetTransitionAsync(transitionId);
            if (result == null)
                return Error("转换历史不存在");

            return Success(result);
        }
        catch (Exception ex)
        {
            return Error(ex.Message);
        }
    }

    /// <summary>
    /// 拒绝工作流
    /// </summary>
    /// <param name="dto">拒绝参数</param>
    /// <returns>是否成功</returns>
    [HttpPost("reject")]
    [HbtPerm("workflow:engine:signoff:reject")]
    public async Task<IActionResult> RejectAsync([FromBody] HbtWorkflowRejectDto dto)
    {
        try
        {
            if (dto == null)
                return Error("请求参数不能为空");

            var result = await _workflowEngine.RejectAsync(dto);
            if (result)
                return Success(true, "拒绝操作成功");
            else
                return Error("拒绝操作失败");
        }
        catch (Exception ex)
        {
            return Error(ex.Message);
        }
    }

    /// <summary>
    /// 手动触发节点转换
    /// </summary>
    /// <param name="dto">转换参数</param>
    /// <returns>是否成功</returns>
    [HttpPost("transit")]
    [HbtPerm("workflow:engine:execution:transit")]
    public async Task<IActionResult> TransitAsync([FromBody] HbtWorkflowTransitDto dto)
    {
        try
        {
            if (dto == null)
                return Error("请求参数不能为空");

            var result = await _workflowEngine.TransitAsync(dto);
            if (result)
                return Success(true, "节点转换成功");
            else
                return Error("节点转换失败");
        }
        catch (Exception ex)
        {
            return Error(ex.Message);
        }
    }

    /// <summary>
    /// 评估条件表达式
    /// </summary>
    /// <param name="dto">条件评估参数</param>
    /// <returns>评估结果</returns>
    [HttpPost("evaluate-condition")]
    [HbtPerm("workflow:engine:execution:evaluate")]
    public async Task<IActionResult> EvaluateConditionAsync([FromBody] HbtConditionEvaluateDto dto)
    {
        try
        {
            if (dto == null)
                return Error("请求参数不能为空");

            var result = await _workflowEngine.EvaluateConditionAsync(dto);
            return Success(result, "条件评估完成");
        }
        catch (Exception ex)
        {
            return Error(ex.Message);
        }
    }

    /// <summary>
    /// 获取工作流实例待办任务
    /// </summary>
    /// <param name="userId">用户ID</param>
    /// <param name="query">查询条件</param>
    /// <returns>待办任务列表</returns>
    [HttpGet("todo/{userId}")]
    [HbtPerm("workflow:engine:execution:query")]
    public async Task<IActionResult> GetTodoTasksAsync(long userId, [FromQuery] HbtWorkflowTodoQueryDto query)
    {
        try
        {
            var result = await _workflowEngine.GetTodoTasksAsync(userId, query);
            return Success(result, "获取待办任务成功");
        }
        catch (Exception ex)
        {
            return Error(ex.Message);
        }
    }

    /// <summary>
    /// 获取工作流实例已办任务
    /// </summary>
    /// <param name="userId">用户ID</param>
    /// <param name="query">查询条件</param>
    /// <returns>已办任务列表</returns>
    [HttpGet("done/{userId}")]
    [HbtPerm("workflow:engine:execution:query")]
    public async Task<IActionResult> GetDoneTasksAsync(long userId, [FromQuery] HbtWorkflowDoneQueryDto query)
    {
        try
        {
            var result = await _workflowEngine.GetDoneTasksAsync(userId, query);
            return Success(result, "获取已办任务成功");
        }
        catch (Exception ex)
        {
            return Error(ex.Message);
        }
    }

    #region 并行工作流管理

    /// <summary>
    /// 创建并行分支
    /// </summary>
    /// <param name="instanceId">工作流实例ID</param>
    /// <param name="branchConfig">分支配置</param>
    /// <returns>分支实例ID列表</returns>
    [HttpPost("parallel/{instanceId}/branches")]
    [HbtPerm("workflow:parallel:create")]
    public async Task<IActionResult> CreateParallelBranchesAsync(long instanceId, [FromBody] HbtParallelBranchConfigDto branchConfig)
    {
        try
        {
            if (branchConfig == null)
                return Error("请求参数不能为空");

            var branchInstanceIds = await _parallelWorkflowEngine.CreateParallelBranchesAsync(instanceId, branchConfig);
            return Success(branchInstanceIds, "并行分支创建成功");
        }
        catch (Exception ex)
        {
            return Error(ex.Message);
        }
    }

    /// <summary>
    /// 检查并行分支状态
    /// </summary>
    /// <param name="instanceId">工作流实例ID</param>
    /// <returns>分支状态信息</returns>
    [HttpGet("parallel/{instanceId}/status")]
    [HbtPerm("workflow:parallel:status")]
    public async Task<IActionResult> CheckBranchStatusAsync(long instanceId)
    {
        try
        {
            var status = await _parallelWorkflowEngine.CheckBranchStatusAsync(instanceId);
            return Success(status, "获取分支状态成功");
        }
        catch (Exception ex)
        {
            return Error(ex.Message);
        }
    }

    /// <summary>
    /// 等待并行分支汇聚
    /// </summary>
    /// <param name="instanceId">工作流实例ID</param>
    /// <param name="timeout">超时时间(分钟)</param>
    /// <returns>是否成功汇聚</returns>
    [HttpPost("parallel/{instanceId}/join")]
    [HbtPerm("workflow:parallel:join")]
    public async Task<IActionResult> WaitForParallelJoinAsync(long instanceId, [FromQuery] int timeout = 30)
    {
        try
        {
            var result = await _parallelWorkflowEngine.WaitForParallelJoinAsync(instanceId, TimeSpan.FromMinutes(timeout));
            return Success(result, result ? "并行分支汇聚成功" : "并行分支汇聚超时");
        }
        catch (Exception ex)
        {
            return Error(ex.Message);
        }
    }

    /// <summary>
    /// 获取并行工作流信息
    /// </summary>
    /// <param name="instanceId">工作流实例ID</param>
    /// <returns>并行工作流信息</returns>
    [HttpGet("parallel/{instanceId}/info")]
    [HbtPerm("workflow:parallel:info")]
    public async Task<IActionResult> GetParallelWorkflowInfoAsync(long instanceId)
    {
        try
        {
            var info = await _parallelWorkflowEngine.GetParallelWorkflowInfoAsync(instanceId);
            return Success(info, "获取并行工作流信息成功");
        }
        catch (Exception ex)
        {
            return Error(ex.Message);
        }
    }

    /// <summary>
    /// 强制汇聚并行分支
    /// </summary>
    /// <param name="instanceId">工作流实例ID</param>
    /// <param name="reason">强制汇聚原因</param>
    /// <returns>是否成功</returns>
    [HttpPost("parallel/{instanceId}/force-join")]
    [HbtPerm("workflow:parallel:force-join")]
    public async Task<IActionResult> ForceJoinBranchesAsync(long instanceId, [FromQuery] string reason = "手动强制汇聚")
    {
        try
        {
            var result = await _parallelWorkflowEngine.ForceJoinBranchesAsync(instanceId, reason);
            return Success(result, result ? "强制汇聚成功" : "强制汇聚失败");
        }
        catch (Exception ex)
        {
            return Error(ex.Message);
        }
    }

    /// <summary>
    /// 处理并行分支完成
    /// </summary>
    /// <param name="branchInstanceId">分支实例ID</param>
    /// <returns>是否处理成功</returns>
    [HttpPost("parallel/branch/{branchInstanceId}/complete")]
    [HbtPerm("workflow:parallel:complete")]
    public async Task<IActionResult> HandleBranchCompletionAsync(long branchInstanceId)
    {
        try
        {
            var result = await _parallelWorkflowEngine.HandleBranchCompletionAsync(branchInstanceId);
            return Success(result, result ? "分支完成处理成功" : "分支完成处理失败");
        }
        catch (Exception ex)
        {
            return Error(ex.Message);
        }
    }

    #endregion

    #region 定时任务管理

    /// <summary>
    /// 创建定时任务
    /// </summary>
    /// <param name="dto">定时任务配置</param>
    /// <returns>定时任务ID</returns>
    [HttpPost("scheduler/tasks")]
    [HbtPerm("workflow:scheduler:create")]
    public async Task<IActionResult> CreateScheduledTaskAsync([FromBody] HbtWorkflowScheduledTaskDto dto)
    {
        try
        {
            if (dto == null)
                return Error("请求参数不能为空");

            var taskId = await _workflowScheduler.CreateScheduledTaskAsync(dto);
            return Success(taskId, "定时任务创建成功");
        }
        catch (Exception ex)
        {
            return Error(ex.Message);
        }
    }

    /// <summary>
    /// 更新定时任务
    /// </summary>
    /// <param name="taskId">任务ID</param>
    /// <param name="dto">更新配置</param>
    /// <returns>是否成功</returns>
    [HttpPut("scheduler/tasks/{taskId}")]
    [HbtPerm("workflow:scheduler:update")]
    public async Task<IActionResult> UpdateScheduledTaskAsync(string taskId, [FromBody] HbtWorkflowScheduledTaskDto dto)
    {
        try
        {
            if (dto == null)
                return Error("请求参数不能为空");

            var result = await _workflowScheduler.UpdateScheduledTaskAsync(taskId, dto);
            return Success(result, result ? "定时任务更新成功" : "定时任务更新失败");
        }
        catch (Exception ex)
        {
            return Error(ex.Message);
        }
    }

    /// <summary>
    /// 删除定时任务
    /// </summary>
    /// <param name="taskId">任务ID</param>
    /// <returns>是否成功</returns>
    [HttpDelete("scheduler/tasks/{taskId}")]
    [HbtPerm("workflow:scheduler:delete")]
    public async Task<IActionResult> DeleteScheduledTaskAsync(string taskId)
    {
        try
        {
            var result = await _workflowScheduler.DeleteScheduledTaskAsync(taskId);
            return Success(result, result ? "定时任务删除成功" : "定时任务删除失败");
        }
        catch (Exception ex)
        {
            return Error(ex.Message);
        }
    }

    /// <summary>
    /// 暂停定时任务
    /// </summary>
    /// <param name="taskId">任务ID</param>
    /// <returns>是否成功</returns>
    [HttpPost("scheduler/tasks/{taskId}/pause")]
    [HbtPerm("workflow:scheduler:pause")]
    public async Task<IActionResult> PauseScheduledTaskAsync(string taskId)
    {
        try
        {
            var result = await _workflowScheduler.PauseScheduledTaskAsync(taskId);
            return Success(result, result ? "定时任务暂停成功" : "定时任务暂停失败");
        }
        catch (Exception ex)
        {
            return Error(ex.Message);
        }
    }

    /// <summary>
    /// 恢复定时任务
    /// </summary>
    /// <param name="taskId">任务ID</param>
    /// <returns>是否成功</returns>
    [HttpPost("scheduler/tasks/{taskId}/resume")]
    [HbtPerm("workflow:scheduler:resume")]
    public async Task<IActionResult> ResumeScheduledTaskAsync(string taskId)
    {
        try
        {
            var result = await _workflowScheduler.ResumeScheduledTaskAsync(taskId);
            return Success(result, result ? "定时任务恢复成功" : "定时任务恢复失败");
        }
        catch (Exception ex)
        {
            return Error(ex.Message);
        }
    }

    /// <summary>
    /// 获取定时任务列表
    /// </summary>
    /// <param name="query">查询条件</param>
    /// <returns>定时任务列表</returns>
    [HttpGet("scheduler/tasks")]
    [HbtPerm("workflow:scheduler:list")]
    public async Task<IActionResult> GetScheduledTasksAsync([FromQuery] HbtWorkflowScheduledTaskQueryDto query)
    {
        try
        {
            var result = await _workflowScheduler.GetScheduledTasksAsync(query);
            return Success(result, "获取定时任务列表成功");
        }
        catch (Exception ex)
        {
            return Error(ex.Message);
        }
    }

    /// <summary>
    /// 获取定时任务详情
    /// </summary>
    /// <param name="taskId">任务ID</param>
    /// <returns>定时任务详情</returns>
    [HttpGet("scheduler/tasks/{taskId}")]
    [HbtPerm("workflow:scheduler:detail")]
    public async Task<IActionResult> GetScheduledTaskAsync(string taskId)
    {
        try
        {
            var result = await _workflowScheduler.GetScheduledTaskAsync(taskId);
            if (result == null)
                return Error("定时任务不存在");

            return Success(result, "获取定时任务详情成功");
        }
        catch (Exception ex)
        {
            return Error(ex.Message);
        }
    }

    /// <summary>
    /// 立即执行定时任务
    /// </summary>
    /// <param name="taskId">任务ID</param>
    /// <returns>是否成功</returns>
    [HttpPost("scheduler/tasks/{taskId}/execute")]
    [HbtPerm("workflow:scheduler:execute")]
    public async Task<IActionResult> ExecuteScheduledTaskNowAsync(string taskId)
    {
        try
        {
            var result = await _workflowScheduler.ExecuteScheduledTaskNowAsync(taskId);
            return Success(result, result ? "定时任务执行成功" : "定时任务执行失败");
        }
        catch (Exception ex)
        {
            return Error(ex.Message);
        }
    }

    /// <summary>
    /// 检查工作流超时
    /// </summary>
    /// <param name="instanceId">工作流实例ID</param>
    /// <returns>是否超时</returns>
    [HttpGet("scheduler/timeout/{instanceId}/check")]
    [HbtPerm("workflow:scheduler:timeout-check")]
    public async Task<IActionResult> CheckWorkflowTimeoutAsync(long instanceId)
    {
        try
        {
            var result = await _workflowScheduler.CheckWorkflowTimeoutAsync(instanceId);
            return Success(result, result ? "工作流已超时" : "工作流未超时");
        }
        catch (Exception ex)
        {
            return Error(ex.Message);
        }
    }

    /// <summary>
    /// 处理工作流超时
    /// </summary>
    /// <param name="instanceId">工作流实例ID</param>
    /// <param name="timeoutAction">超时动作</param>
    /// <returns>是否处理成功</returns>
    [HttpPost("scheduler/timeout/{instanceId}/handle")]
    [HbtPerm("workflow:scheduler:timeout-handle")]
    public async Task<IActionResult> HandleWorkflowTimeoutAsync(long instanceId, [FromQuery] string timeoutAction = "suspend")
    {
        try
        {
            var result = await _workflowScheduler.HandleWorkflowTimeoutAsync(instanceId, timeoutAction);
            return Success(result, result ? "超时处理成功" : "超时处理失败");
        }
        catch (Exception ex)
        {
            return Error(ex.Message);
        }
    }

    /// <summary>
    /// 获取超时配置
    /// </summary>
    /// <param name="schemeId">流程定义ID</param>
    /// <returns>超时配置</returns>
    [HttpGet("scheduler/timeout/{schemeId}/config")]
    [HbtPerm("workflow:scheduler:timeout-config")]
    public async Task<IActionResult> GetTimeoutConfigAsync(long schemeId)
    {
        try
        {
            var result = await _workflowScheduler.GetTimeoutConfigAsync(schemeId);
            if (result == null)
                return Error("未找到超时配置");

            return Success(result, "获取超时配置成功");
        }
        catch (Exception ex)
        {
            return Error(ex.Message);
        }
    }

    #endregion

}